import { FC, ReactElement, memo } from 'react'
import { Modal, Button } from 'antd'

interface IProps {
  visible: boolean
  hide: () => void
  filePath: string
}

const PreviewPdf: FC<IProps> = ({ visible, hide, filePath }): ReactElement => {
  const handleCancel = () => {
    hide()
  }

  return (
    <Modal
      title="预览pdf"
      open={visible}
      onCancel={handleCancel}
      width="80%"
      okText="确认"
      cancelText="取消"
      maskClosable={false}
      bodyStyle={{
        height: `${window.innerHeight * 0.75}px`,
        overflowY: 'auto'
      }}
      footer={[
        // 重点：定义右下角
        <Button onClick={handleCancel}>关闭</Button>
      ]}
    >
      <iframe src={filePath} width="100%" height="100%" />
    </Modal>
  )
}

export default memo(PreviewPdf)
